﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KCMS.DataAcsess.Interfaces;
using StructureMap;
using AutoMapper;
using KCMS.BusinessLogic.Models;
using KCMS.BusinessLogic.Interfaces;


namespace KCMS.BusinessLogic.Engine
{
    public class OrderItemService:IOrderItemService
    {
        private IOrderItemManager orderItemManager = ObjectFactory.GetInstance<IOrderItemManager>();
        public Models.OrderItem getById(Guid id)
        {
            DataAcsess.Entitys.OrderItemEntity orderItemEntity = orderItemManager.getById(id);
            return Mapper.Map<DataAcsess.Entitys.OrderItemEntity, Models.OrderItem>(orderItemEntity);
        }
       
        public IEnumerable<Models.OrderItem> getAll()
        {
            var model = from t in orderItemManager.getAll()
                        select t;
            return Mapper.Map<IEnumerable<DataAcsess.Entitys.OrderItemEntity>, IEnumerable<Models.OrderItem>>(model);

        }

        public void update(OrderItem orderItem)
        {
            orderItemManager.update(Mapper.Map<OrderItem, DataAcsess.Entitys.OrderItemEntity>(orderItem));
        }


        public void save(OrderItem orderItem)
        {
            orderItemManager.save(Mapper.Map<OrderItem, DataAcsess.Entitys.OrderItemEntity>(orderItem));
        }


        public void delete(Guid id)
        {
            orderItemManager.delete(id);
        }


        public IEnumerable<OrderItem> getByOrder(Guid orderId)
        {
            return (from t in getAll()
                    where t.OrderId.Equals(orderId)
                    select t).ToList();
        }
    }
}
